import { Dialog, Message } from '../modal'


export function useConfirmBoolean(api: any, callback: any, prop: string, trueText: string, falseText: string) {
  return async (params: any): Promise<void> => {
    const result = params[prop]
    const text = result ? trueText : falseText
    try {
      await Dialog.confirm({
        content: `确认要${text}吗？`,
        onOk: async (): Promise<void> => {
          const result = await api(params);
          if (result !== false) {
            Message.success(`${text}成功`)
            await callback()
          }
        },
        title: text,
      }).catch(_ => {})
    } catch {
      params[prop] = !result
    }
  }
}
